<template>
	<div class="root">
		<el-table
			:data="tableData"
			stripe
			style="width: 100%">
			<el-table-column
				prop="id"
				label="ID"
				width="80">
			</el-table-column>
			<el-table-column
				prop="user_id"
				width="120"
				label="用户ID">
			</el-table-column>
			<el-table-column
				prop="content"
				label="日志内容"
			>
			</el-table-column>
			<el-table-column
				prop="create_time"
				label="时间">
			</el-table-column>
		</el-table>
		<div class="pagenation">
			<el-pagination
				background
				@current-change="judgePage"
				@prev-click="prevPage"
				@next-click="nextPage"
				layout="prev, pager, next"
				:total="total">
			</el-pagination>
		</div>
	</div>
</template>

<script>
export default {
		data() {
			return {
				tableData: [],
				page:1,
				total:0
			}
		},
		created() {
			this.getLog()
		},
		methods:{
			getLog(type){
				let page = this.page
				if(type == 1){
					// 上一页
					page--
				}else if(type==2){
					// 下一页
					page++
				}else{
					page
				}
				console.log(page)
				this.$axios.post('Role/get_log',{page:page},{headers:{token:sessionStorage.getItem('token')}})
				.then(res=>{
					console.log(res)
					if(res.data.code==2000){
						this.tableData = res.data.data.list
						this.total = res.data.data.count
					}else{
						this.$message.error(res.data.msg)
					}
				})
			},
			// 下一页
			nextPage(){
				console.log('下一页')
				this.getLog(2)
			},
			// 上一页
			prevPage(){
				console.log('上一页')
				this.getLog(1)
			},
			judgePage(e){
				this.page=e
				this.getLog()
				console.log('直接')
			}
		}
	}
</script>

<style scoped lang="less">
	.root{
		padding: 50px;
	}	
	.pagenation{
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 60px;
	}
</style>
